package com.xhwl.centiotdata.suppliersystem.eesd.ntescar;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Maps;
import com.xhwl.centiotdata.mq.producer.GeneralProducer;
import com.xhwl.centiotdata.pojo.dto.eesd.EesdConfigDTO;
import com.xhwl.centiotdata.service.cent.IDeviceCentService;
import com.xhwl.centiotdata.service.cent.IEesdCentService;
import com.xhwl.centiotdata.utils.RedisUtils;
import com.xhwl.common.constant.cent.alarm.AlarmConstant;
import com.xhwl.common.dto.cent.device.DeviceDTO;
import com.xhwl.common.dto.cent.eesd.EnergyStorageCarDetailSyncDTO;
import com.xhwl.common.dto.cent.iotdata.ntescar.NtEsCarPullRespDTO;
import com.xhwl.common.enums.device.DeviceTypeEnum;
import com.xhwl.common.exception.DataException;
import com.xhwl.common.pojo.cent.alarm.AlarmManagement;
import com.xhwl.common.pojo.cent.energy.EnergyStorageCarBatteryDetail;
import com.xhwl.common.pojo.cent.energy.EnergyStorageCarDetail;
import com.xhwl.common.query.cent.device.DevicePageQuery;
import com.xhwl.common.utils.ChkUtil;
import com.xhwl.common.utils.StringUtils;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 南投储能车
 */
@RestController
@Slf4j
public class NtEsCarApiHandler {
    /**
     * 接口为增量，第一次拉去默认从20秒前的数据获取
     */
    private static final int DEFAULT_PERIOD = 20 * 1000;
    private static final int REQUEST_RECORD_COUNT = 2000;
    private static final String LAST_TIMESTAMP_KEY_PREFIX = "NT_ESCAR_LAST_TIMESTAMP_";
    private static final String NT_TOKEN_KEY = "NT_TOKEN_KEY";
    @Autowired
    private RedisUtils redisUtils;
    @Autowired
    private IEesdCentService iEesdCentService;
    @Autowired
    private IDeviceCentService iDeviceCentService;
    @Autowired
    private GeneralProducer generalProducer;

    /**
     * 拉取数据，最新的一条
     */
    @PostMapping("/ntescar/pullRecord")
    public void pullRecord(@RequestBody EesdConfigDTO eesdConfigDTO) {
        if (eesdConfigDTO.getProjectId() == null || eesdConfigDTO.getNtEsCar() == null) {
            log.warn("pull[南投储能车]实时数据配置有误");
            return;
        }
        String token;
        if (redisUtils.get(NT_TOKEN_KEY) != null) {
            token = redisUtils.get(NT_TOKEN_KEY).toString();
        } else {
            token = getToken(eesdConfigDTO.getNtEsCar());
        }
        //获取设备信息
        List<EnergyStorageCarDeviceDTO> esCarDevices = listEnergyStorageCarDevices(eesdConfigDTO.getProjectId());
        if (!CollectionUtils.isEmpty(esCarDevices)) {
            List<EnergyStorageCarDetailSyncDTO> dots = new ArrayList<>(esCarDevices.size());
            List<AlarmManagement> alarmManagements = new ArrayList<>();
            esCarDevices.forEach(device -> {
                DeviceDTO carDevice = device.getCarDevice();
                // 查询南投储能车实时数据
                NtEsCarPullRespDTO respDTO = pullNewByEquipment(eesdConfigDTO, carDevice,token);
                if (respDTO != null) {
                    Date now = new Date();
                    EnergyStorageCarDetailSyncDTO dto = convertToNtESCarDTO(eesdConfigDTO.getProjectId(), device, respDTO, alarmManagements);
                    dots.add(dto);
                }
            });
            //同步数据
            if (dots.size() > 0) {
                iEesdCentService.esCarDetailSync(dots);
            }
            //发送告警数据
            for (AlarmManagement alarmManagement : alarmManagements) {
                generalProducer.send(AlarmConstant.DAHUA_ALARM_TOPIC, alarmManagement);
            }

        }
    }

    /**
     * 获取储能车设备信息
     */
    private List<EnergyStorageCarDeviceDTO> listEnergyStorageCarDevices(Integer projectId) {
        DevicePageQuery deviceQuery = new DevicePageQuery();
        deviceQuery.setProjectId(projectId);
        deviceQuery.setDeviceTypeIdList(Arrays.asList(DeviceTypeEnum.EnergyStorageCar.getCode(), DeviceTypeEnum.EnergyStorageCarPCS.getCode(), DeviceTypeEnum.EnergyStorageCarBattery.getCode(), DeviceTypeEnum.EnergyStorageCarBatteryCluster.getCode()));
        List<DeviceDTO> deviceDTOS = iDeviceCentService.listDevice(null, deviceQuery);
        if (CollectionUtils.isEmpty(deviceDTOS)) {
            return Collections.emptyList();
        }
        //设备类型拆为：储能车，逆变器，储能车电池整体，储能车电池簇
        //储能车有实际第三方id,其他设备类型，逆变器：第三方id-PCS, 储能车电池整体:第三方id-Battery ,储能车电池簇: 第三方id-Cluster-序号
        List<DeviceDTO> carDeviceDTOs = deviceDTOS.stream().filter(device -> DeviceTypeEnum.EnergyStorageCar.getCode().equals(device.getDeviceTypeId())).collect(Collectors.toList());
        return carDeviceDTOs.stream().map(carDevice -> {
            EnergyStorageCarDeviceDTO deviceDTO = new EnergyStorageCarDeviceDTO();
            deviceDTO.setCarDevice(carDevice);
            deviceDTO.setPcsDevice(
                    deviceDTOS.stream().filter(device -> (carDevice.getThirdDeviceId() + "-PCS").equals(device.getThirdDeviceId()))
                            .findFirst().orElseThrow(() -> new DataException("设备配置不全"))
            );
            deviceDTO.setBatteryDevice(
                    deviceDTOS.stream().filter(device -> (carDevice.getThirdDeviceId() + "-Battery").equals(device.getThirdDeviceId()))
                            .findFirst().orElseThrow(() -> new DataException("设备配置不全"))
            );
            deviceDTO.setBatteryCluster(
                    deviceDTOS.stream().filter(device -> StringUtils.isNotEmpty(device.getThirdDeviceId())
                            && device.getThirdDeviceId().startsWith(carDevice.getThirdDeviceId() + "-Cluster-"))
                            .sorted(Comparator.comparing(DeviceDTO::getId))
                            .collect(Collectors.toList())
            );
            return deviceDTO;
        }).collect(Collectors.toList());
    }

    /**
     * 只需要最新的一条
     */
    private NtEsCarPullRespDTO pullNewByEquipment(EesdConfigDTO eesdConfigDTO, DeviceDTO carDevice,String token) {
        String lastTimeStamp = getLastTimeStamp(eesdConfigDTO.getProjectId(), carDevice.getId());
        JSONObject preJson = null;
        JSONObject currJson = null;
        Integer retureRecordCount = 0;
        do {
            preJson = currJson;
            currJson = pullByEquipment(eesdConfigDTO.getNtEsCar(), carDevice.getThirdDeviceId(), lastTimeStamp,token);
            retureRecordCount = currJson.getInteger("RetureRecordCount");
            lastTimeStamp = currJson.getString("maxTimeStamp");
        } while (retureRecordCount >= REQUEST_RECORD_COUNT);
        NtEsCarPullRespDTO resp = null;
        if (retureRecordCount > 0) {
            JSONArray dataList = currJson.getJSONArray("dataList");
            List<NtEsCarPullRespDTO> list = dataList.toJavaList(NtEsCarPullRespDTO.class);
            resp = list.get(list.size() - 1);
        } else if (preJson != null) {
            JSONArray dataList = preJson.getJSONArray("dataList");
            if (dataList != null) {
                List<NtEsCarPullRespDTO> list = dataList.toJavaList(NtEsCarPullRespDTO.class);
                resp = list.get(list.size() - 1);
            }
        }
        //更新最大时间戳
        updateLastTimeStamp(eesdConfigDTO.getProjectId(), carDevice.getId(), lastTimeStamp);
        return resp;
    }

    public static String getLastTimestampKey(Integer projectId, Integer deviceId) {
        return LAST_TIMESTAMP_KEY_PREFIX + projectId + "_" + deviceId;
    }

    private String getLastTimeStamp(Integer projectId, Integer deviceId) {
        //redis获取上次结束时间
        String lastTimestamp = (String) redisUtils.get(getLastTimestampKey(projectId, deviceId));
        if (lastTimestamp != null) {
            return lastTimestamp;
        }
        return ((System.currentTimeMillis() - DEFAULT_PERIOD) / 1000) + "-0";
    }

    private void updateLastTimeStamp(Integer projectId, Integer deviceId, Object maxTimeStamp) {
        //更新最大记录条数
        redisUtils.set(getLastTimestampKey(projectId, deviceId), maxTimeStamp);
    }


    private String getToken(EesdConfigDTO.NtEsCar ntEsCar) {
        String url = ntEsCar.getHost() + "/app/v1.0/session/token/apply";
        log.info("请求token-config:{}", ntEsCar);
        log.info("请求token-url:{}", url);
        Map<String, Object> map = Maps.newHashMap();
        map.put("appId", ntEsCar.getAppId());
        map.put("appSecret", ntEsCar.getAppSecret());
        map.put("scope", "all");
        //发起鉴权
        String result = HttpUtil.post(url, JSON.toJSONString(map), 3000);
        if (result == null) {
            throw new RuntimeException("result是null");
        }
        log.info("请求token-response:{}", result);
        Map<String, Object> res = JSON.parseObject(result, Map.class);
        if (res == null) {
            throw new RuntimeException(result);
        }
        if (ChkUtil.getInteger(res.get("errCode")) != 0) {
            throw new RuntimeException(result);
        }
        redisUtils.setWithMinute(NT_TOKEN_KEY,(String) res.get("token"),720);
        return (String) res.get("token");
    }

    private JSONObject pullByEquipment(EesdConfigDTO.NtEsCar ntEsCar, String equipmentId, String lastTimeStamp,String token) {
        String url = ntEsCar.getHost() + "/app/v1.0/equipment/data/pullByEquipment";
        log.info("请求pullByEquipment-config:{}", ntEsCar);
        log.info("请求pullByEquipment-url:{}", url);
        Map<String, Object> map = Maps.newHashMap();
        map.put("equipmentId", equipmentId);
        //时间戳+id
        map.put("lastTimeStamp", lastTimeStamp);
        map.put("requestRecordCount", REQUEST_RECORD_COUNT);
        String result = HttpRequest.post(url)
                .header("token", token)
                .body(JSON.toJSONString(map)).execute().body();
        if (result == null) {
            throw new RuntimeException("result是null");
        }
        log.info("请求pullByEquipment-response:{}", result);
        JSONObject respJson = JSONObject.parseObject(result);
        if (ChkUtil.getInteger(respJson.get("errCode")) != 0) {
            throw new RuntimeException(result);
        }
        return respJson;
    }

    private EnergyStorageCarDetailSyncDTO convertToNtESCarDTO(Integer projectId, EnergyStorageCarDeviceDTO carDeviceDTO, NtEsCarPullRespDTO respDTO, List<AlarmManagement> alarmManagements) {
        respDTO.setDataMap(JSONObject.parseObject(respDTO.getData(), Map.class));
        EnergyStorageCarDetailSyncDTO dto = new EnergyStorageCarDetailSyncDTO();
        EnergyStorageCarDetail carDetail = convertToCarDetail(projectId, carDeviceDTO.getCarDevice(), carDeviceDTO.getPcsDevice().getId(), respDTO, alarmManagements);
        dto.setCarDetail(carDetail);
        dto.setBatteryDetails(convertToBatteryDetail(projectId, respDTO.getDataMap(), carDeviceDTO, alarmManagements));
        return dto;
    }

    /*private List<EnergyStorageCarDetailSyncDTO> convertToNtESCarDTO(Integer projectId, Integer deviceId, JSONArray jsonArray) {
        if (jsonArray.isEmpty()) {
            return Collections.emptyList();
        }
        List<NtEsCarPullRespDTO> pullResp = jsonArray.toJavaList(NtEsCarPullRespDTO.class);
        List<EnergyStorageCarDetailSyncDTO> list = new ArrayList<>(pullResp.size());
        Date date = new Date();
        for (int i = 0; i < pullResp.size(); i++) {
            NtEsCarPullRespDTO respDTO = pullResp.get(i);
            list.add(convertToNtESCarDTO(projectId, deviceId, respDTO, date));
        }
        return list;
    }*/

    private EnergyStorageCarDetail convertToCarDetail(Integer projectId, DeviceDTO carDevice, Integer pcsDeviceId, NtEsCarPullRespDTO respDTO, List<AlarmManagement> alarmManagements) {
        EnergyStorageCarDetail carDetail = new EnergyStorageCarDetail();
        carDetail.setProjectId(projectId);
        carDetail.setDeviceId(carDevice.getId());
        carDetail.setRatedPower(carDevice.getAttributeJson().getDouble("ratedPower"));
        carDetail.setBatteryCapacity(carDevice.getAttributeJson().getDouble("batteryCapacity"));
        carDetail.setCustomerId(respDTO.getCustomerId());
        carDetail.setEquipmentId(respDTO.getEquipmentId());
        carDetail.setEquipmentTypeId(respDTO.getEquipmentTypeId());
        carDetail.setDataId(respDTO.getId());
        carDetail.setDataStructVersion(respDTO.getDataStructVersion());
        carDetail.setCollectTime(respDTO.getCollectTime());
        carDetail.setUploadTime(respDTO.getUploadTime());
        carDetail.setWarningLevel(respDTO.getWarningLevel());
        carDetail.setWarningMsg(respDTO.getWarningMsg());
        //从data中解析数据
        Map<String, String> dataMap = respDTO.getDataMap();
        carDetail.setModctrl(Integer.valueOf(dataMap.get("modctrl")));
        carDetail.setSpcs(Integer.valueOf(dataMap.get("spcs")));
        carDetail.setCdrun(Integer.valueOf(dataMap.get("cdrun")));
        carDetail.setCdchg(Integer.valueOf(dataMap.get("cdchg")));
        carDetail.setBatteryEnc(Double.valueOf(dataMap.getOrDefault("enc", "0")));
        carDetail.setBatteryEnd(Double.valueOf(dataMap.getOrDefault("end", "0")));
        carDetail.setPcsStr1Udc(Double.valueOf(dataMap.getOrDefault("PCS_STR_1_Udc", "0")));
        carDetail.setPcsStr1Idc(Double.valueOf(dataMap.getOrDefault("PCS_STR_1_Idc", "0")));
        carDetail.setPcsStr1Pdc(Double.valueOf(dataMap.getOrDefault("PCS_STR_1_Pdc", "0")));
        carDetail.setPcsStr2Udc(Double.valueOf(dataMap.getOrDefault("PCS_STR_2_Udc", "0")));
        carDetail.setPcsStr2Idc(Double.valueOf(dataMap.getOrDefault("PCS_STR_2_Idc", "0")));
        carDetail.setPcsStr2Pdc(Double.valueOf(dataMap.getOrDefault("PCS_STR_2_Pdc", "0")));
        carDetail.setPcsStr3Udc(Double.valueOf(dataMap.getOrDefault("PCS_STR_3_Udc", "0")));
        carDetail.setPcsStr3Idc(Double.valueOf(dataMap.getOrDefault("PCS_STR_3_Idc", "0")));
        carDetail.setPcsStr3Pdc(Double.valueOf(dataMap.getOrDefault("PCS_STR_3_Pdc", "0")));
        carDetail.setPcsStr4Udc(Double.valueOf(dataMap.getOrDefault("PCS_STR_4_Udc", "0")));
        carDetail.setPcsStr4Idc(Double.valueOf(dataMap.getOrDefault("PCS_STR_4_Idc", "0")));
        carDetail.setPcsStr4Pdc(Double.valueOf(dataMap.getOrDefault("PCS_STR_4_Pdc", "0")));
        carDetail.setPcsPdc(carDetail.getPcsStr1Pdc() + carDetail.getPcsStr2Pdc() + carDetail.getPcsStr3Pdc() + carDetail.getPcsStr4Pdc());

        carDetail.setAcpfa(Double.valueOf(dataMap.getOrDefault("acpfa", "0")));
        carDetail.setAcpfb(Double.valueOf(dataMap.getOrDefault("acpfb", "0")));
        carDetail.setAcpfc(Double.valueOf(dataMap.getOrDefault("acpfc", "0")));
        carDetail.setAcca(Double.valueOf(dataMap.getOrDefault("acca", "0")));
        carDetail.setAccb(Double.valueOf(dataMap.getOrDefault("accb", "0")));
        carDetail.setAccc(Double.valueOf(dataMap.getOrDefault("accc", "0")));
        carDetail.setCos(Double.valueOf(dataMap.getOrDefault("cos", "0")));
        carDetail.setEptp(Double.valueOf(dataMap.getOrDefault("eptp", "0")));
        carDetail.setEptn(Double.valueOf(dataMap.getOrDefault("eptn", "0")));
        carDetail.setEqtp(Double.valueOf(dataMap.getOrDefault("eqtp", "0")));
        carDetail.setEqtn(Double.valueOf(dataMap.getOrDefault("eqtn", "0")));
        //处理逆变器告警字段
        Map<String, String> warnField = new HashMap<>();
        warnField.put("almouac", dataMap.get("almouac"));
        warnField.put("almuuac", dataMap.get("almuuac"));
        warnField.put("almfreqhac", dataMap.get("almfreqhac"));
        warnField.put("almfreqlac", dataMap.get("almfreqlac"));
        warnField.put("almovdc", dataMap.get("almovdc"));
        warnField.put("almuvdc", dataMap.get("almuvdc"));
        warnField.put("almabncommstop", dataMap.get("almabncommstop"));
        warnField.put("prtstop", dataMap.get("prtstop"));
        warnField.put("almopercondlimitstop", dataMap.get("almopercondlimitstop"));
        warnField.put("ataccont", dataMap.get("ataccont"));
        carDetail.setWarningField(JSON.toJSONString(warnField));
        alarmManagements.addAll(createAlarmManagement(projectId, pcsDeviceId, warnField));

        carDetail.setCreatedAt(new Date());
        carDetail.setUpdatedAt(new Date());
        return carDetail;
    }

    private List<EnergyStorageCarBatteryDetail> convertToBatteryDetail(Integer projectId, Map<String, String> dataMap, EnergyStorageCarDeviceDTO carDeviceDTO, List<AlarmManagement> alarmManagements) {
        Map<String, String> map = new HashMap<>(dataMap.size());
        //key统一转换成小写
        dataMap.forEach((key, value) -> map.put(key.toLowerCase(), value));
        //拿到电池簇数量
        int batterySize = carDeviceDTO.getBatteryCluster().size();
        List<EnergyStorageCarBatteryDetail> list = new ArrayList<>(batterySize + 1);
        //i=0表示电池整体
        for (int i = 0; i < batterySize + 1; i++) {
            String prefix = i == 0 ? "" : ("bms_cbms_" + i + "_");
            String warnPrefix = i == 0 ? "gbms" : ("bms_cbms_" + i + "_");
            DeviceDTO device = i == 0 ? carDeviceDTO.getBatteryDevice() : carDeviceDTO.getBatteryCluster().get(i - 1);
            Integer deviceId = device.getId();
            EnergyStorageCarBatteryDetail batteryDetail = new EnergyStorageCarBatteryDetail();
            batteryDetail.setBmsNo(i);
            batteryDetail.setLabel(device.getName());
            batteryDetail.setSbat(Integer.valueOf(map.get(prefix + "sbat")));
            batteryDetail.setKcd(Integer.valueOf(map.get(prefix + "kcd")));
            batteryDetail.setUbat(Double.valueOf(map.getOrDefault(prefix + "ubat", "0")));
            batteryDetail.setIbat(Double.valueOf(map.getOrDefault(prefix + "ibat", "0")));
            batteryDetail.setSoc(Double.valueOf(map.getOrDefault(prefix + "soc", "0")));
            batteryDetail.setSoh(Double.valueOf(map.getOrDefault(prefix + "soh", "0")));
            batteryDetail.setUbn(Double.valueOf(map.getOrDefault(prefix + "ubn", "0")));
            batteryDetail.setUbm(Double.valueOf(map.getOrDefault(prefix + "ubm", "0")));
            batteryDetail.setUdiffmax(Double.valueOf(map.getOrDefault(prefix + "udiffmax", "0")));
            batteryDetail.setTbn(Double.valueOf(map.getOrDefault(prefix + "tbn", "0")));
            batteryDetail.setTbm(Double.valueOf(map.getOrDefault(prefix + "tbm", "0")));
            batteryDetail.setTdiffmax(Double.valueOf(map.getOrDefault(prefix + "tdiffmax", "0")));
            batteryDetail.setNbmu(map.get(prefix + "nbmu"));
            batteryDetail.setNbnu(map.get(prefix + "nbnu"));
            batteryDetail.setNbnt(map.get(prefix + "nbnt"));
            batteryDetail.setNbmt(map.get(prefix + "nbmt"));
            //处理电池告警字段
            Map<String, String> warnField = new HashMap<>();
            warnField.put("tvo", map.get(warnPrefix + "tvo"));
            warnField.put("tvu", map.get(warnPrefix + "tvu"));
            warnField.put("htc", map.get(warnPrefix + "htc"));
            warnField.put("ltc", map.get(warnPrefix + "ltc"));
            warnField.put("cvo", map.get(warnPrefix + "cvo"));
            warnField.put("cvu", map.get(warnPrefix + "cvu"));
            warnField.put("dco", map.get(warnPrefix + "dco"));
            warnField.put("cco", map.get(warnPrefix + "cco"));
            warnField.put("htd", map.get(warnPrefix + "htd"));
            warnField.put("ltd", map.get(warnPrefix + "ltd"));
            warnField.put("cim", map.get(warnPrefix + "cim"));
            warnField.put("tim", map.get(warnPrefix + "tim"));
            warnField.put("lsoc", map.get(warnPrefix + "lsoc"));
            warnField.put("lires", map.get(warnPrefix + "lires"));
            alarmManagements.addAll(createAlarmManagement(projectId, deviceId, warnField));
            batteryDetail.setWarningField(JSON.toJSONString(warnField));
            list.add(batteryDetail);
        }
        return list;
    }

    public List<AlarmManagement> createAlarmManagement(Integer projectId, Integer deviceId, Map<String, String> map) {
        List<AlarmManagement> list = new ArrayList<>(map.size());
        map.forEach((key, value) -> {
            //1 表示发生
            if ("1".equals(value)) {
                list.add(createAlarmManagement(projectId, deviceId, getAlarmInventoryCode(key)));
            }
        });
        return list;
    }

    public AlarmManagement createAlarmManagement(Integer projectId, Integer deviceId, String alarmInventoryCode) {
        AlarmManagement alarmManagement = new AlarmManagement();
        alarmManagement.setProjectId(projectId);
        alarmManagement.setDeviceId(deviceId);
        alarmManagement.setAlarmInventoryCode(alarmInventoryCode);
        alarmManagement.setAlarmTime(new Date());
        return alarmManagement;
    }

    private String getAlarmInventoryCode(String key) {
        switch (key) {
            case "almouac":
                //交流侧电压过压
                return "36157502";
            case "almuuac":
                //交流侧电压欠压
                return "94328743";
            case "almfreqhac":
                //交流侧频率过高
                return "66262728";
            case "almfreqlac":
                //交流侧频率过低
                return "27538689";
            case "almovdc":
                //直流侧过压
                return "77237548";
            case "almuvdc":
                //直流侧欠压
                return "60459681";
            case "almabncommstop":
                //通信异常停机
                return "96788986";
            case "prtstop":
                //保护停机
                return "98373394";
            case "almopercondlimitstop":
                //运行条件超限停机
                return "67266770";
            case "ataccont":
                //交流接触器状态
                return "33851995";
            case "tvo":
                //总电压过压 || 电压过压
                return "56001475";
            case "tvu":
                // 总电压欠压 || 电压欠压
                return "30150688";
            case "htc":
                //充电温度高
                return "30282051";
            case "ltc":
                //充电温度低
                return "59952721";
            case "cvo":
                //单体过压
                return "24610122";
            case "cvu":
                //单体欠压
                return "00725488";
            case "dco":
                //放电过流
                return "99864194";
            case "cco":
                //充电过流
                return "12820336";
            case "htd":
                //放电温度高
                return "92892573";
            case "ltd":
                //放电温度低
                return "82042584";
            case "cim":
                //电芯不均衡
                return "14978969";
            case "tim":
                //温度不均衡
                return "41300124";
            case "lsoc":
                //SOC低
                return "76171112";
            case "lires":
                //绝缘电阻低
                return "36210201";
            default:
                throw new DataException("暂不支持的状态");
        }
    }

    @Data
    public static class EnergyStorageCarDeviceDTO {
        private DeviceDTO carDevice;
        private DeviceDTO pcsDevice;
        private DeviceDTO batteryDevice;
        private List<DeviceDTO> batteryCluster;
    }
}
